package engine.parsers.impl;


import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndEntry;

import engine.content.IContent;
import engine.content.RSSContent;
import engine.parsers.IParser;
import engine.services.IContentService;


public class DilbertRSSParser  implements IParser{

	@Override
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public IContent parse(IContent content, IContentService contentService) throws Exception {
		RSSContent rss = (RSSContent)content;
		SyndEntry entry = rss.getFeedIterator().next();
		
		// we found out entry, let's get the image url from the 
		// description field.
		SyndContent description = entry.getDescription();
		String imgStr = description.getValue();
		int startIndex = (imgStr.indexOf("src") + 5);
		int endIndex = imgStr.indexOf("\"", startIndex);
		imgStr = imgStr.substring(startIndex, endIndex);
		return contentService.getResponse(imgStr);
	}
}